<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue中动画的封装</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <fade :show="show">
            <div>Hello World</div>
        </fade>
        <fade :show="show">
            <h1>Hello World</h1>
        </fade>
        
        <button @click="handleClick">toggle</button>
    </div>
    <script>
        Vue.component("fade", {
            props : ['show'],
            template : `<transition @before-enter="handleBeforeEnter"
                            @enter="handleEnter"
                            @after-enter="handleAfterEnter">
                            <slot v-if="show">{{show}}</slot>
                        </transition>`,
            methods : {
                handleBeforeEnter : function (el) {
                    el.style.color = 'red'
                },
                handleEnter : function (el, done) {
                    setTimeout(()=>{
                        el.style.color = 'green'
                    }, 2000)

                    setTimeout(() => {
                        done()
                    }, 4000)
                },
                handleAfterEnter : function (el) {
                    el.style.color = 'yellow'
                }
            }
        })

        new Vue({
            el : "#app",
            data : {
                show : false
            },
            methods : {
                handleClick : function () {
                    this.show = !this.show ;
                }
            }
        })
    </script>
</body>
</html>